import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observer, Observable, ObservableLike } from 'rxjs';
import * as gc from 'src/app/global/globalconst';


export class User{
  id:number;// 表自增主键
  user_logname:String;// 微信昵称
  user_name:String;// 真实姓名
  weixin_name:String;// openid
  is_dev:number;// 1表示开发人员，0表示不是
  user_password:String;
  receive_process:number;// 1表示接收刷卡推送
  receive_bp:number;// 1表示接收白坯推送
  receive_cp:number;// 1表示接收成品推送
}

const contextPath:string = gc.server;
const pre:string="/user";

@Injectable({
  providedIn: 'root'
})
export class UserService {

  url = {
    'isDev':contextPath + pre + '/isDev',
    'getAll':contextPath + pre + '/g'
  }
  constructor(
    private http:HttpClient
  ) { }

  /**
   * 获取所有微信号
   */
  getAll():Observable<User[]>{
    const url = this.url.getAll;
    return this.http.get<User[]>(url);
  }

  /**
   * 返回微信号是否开发人员
   * @param openid 微信用户openid
   */
  isDev(openid:String):Observable<Boolean>{
    const url = this.url.isDev + '/' + openid;
    console.log('检测是否开发者的URL = ' + url);
    
    return this.http.get<Boolean>(url);
  }
}
